package com.jpa.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.jpa.dao.UserDao;
import com.jpa.dao.UserDaoImpl;
import com.jpa.entity.AccountInfo;
import com.jpa.entity.UserInfo;


public class UserServiceImpl implements UserService{
	
	private UserDao userDao = new UserDaoImpl(); 

	
	public AccountInfo createNewAccount(String user, String pwd, Integer init) {
		// 封装域对象
		AccountInfo accountInfo = new AccountInfo(); 
		UserInfo userInfo = new UserInfo(); 
		userInfo.setUsername(user); 
		userInfo.setPassword(pwd); 
		accountInfo.setBalance(init); 
		accountInfo.setUserInfo(userInfo); 
		// 调用持久层，完成数据的保存
		return userDao.save(accountInfo); 
	}


	public List<AccountInfo> findAll() {
		return userDao.findAll();
	}


	@Override
	public AccountInfo findById(int accountId) {
		return userDao.findById(accountId);
	}


	@Override
	public void remove(AccountInfo accountInfo) {
		userDao.remove(accountInfo.getAccountId());
		
	}


	@Override
	public void update(AccountInfo accountInfo) {
		userDao.update(accountInfo);
		
	}
	

}
